Sample code to call static or dynamic runtime modules using MinGW
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tested using minGW 3.4.2 and 4.8.1  and  minGW-w64 4.8.1

The source files you need are:

File name        Folder                     Description
apitest.c        Samples\c                  main source code file for C
dris.h           Samples\c                  contains the DRIS structure
dpwin32_coff.obj Samples\c\object_modules   static object modules e.g. dpwin32_coff.obj, dpwin64.obj
libdpwin32.a     Samples\c\import_libs      contains the function definitions for dpwin32.dll

To link the static runtime module compile like this:

32-bit:
gcc -m32 ..\..\apitest.c ..\..\object_modules\dpwin32_coff.obj -o ObjTest.exe

64-bit:
gcc -m64 ..\..\apitest.c ..\..\object_modules\dpwin64.obj -o ObjTest64.exe
(please ignore the warning about uuid.lib)

Alternatively to link with the dynamic runtime module compile like this:

32-bit:
gcc -m32 ..\..\apitest.c -L..\..\import_libs -ldpwin32 -o DllTest.exe

64-bit:
gcc -m64 ..\..\apitest.c -L..\..\import_libs -ldpwin64 -o DllTest64.exe

The sample code contains 10 functions. You will not need to use all these
functions in your code. Just use which ever functions are most appropriate
and customise in your own way. The sample code is just a guide. You should
implement the protection in a stronger way using the techniques described in
the "Increasing your Protection" chapter of the manual.

Code marked with !!!! are places where you should customise the sample code so
that it will work properly:

* Change the MY_SDSN value to the value of your SDSN
* Change the MY_PRODCODE value to the Product Code in the dongle
* Change the MyAlgorithm code (if you call a user algorithm)
* Change the CryptDRIS code (if you encrypt the DRIS)
* Change the CryptApiData (if you encrypt Data you send to our API)
* Change the MyRWAlgorithm code (if encrypt Data you send to our API using the R/W algorithm)

You will also probably want to replace our error messages with your own.

Note - if you are link the static module dpwin32_coff.obj then you should protect your program.
If you are linking to dpwin32.dll then you need to protect dpwin32.dll and *not* your program.
Because your program is linked to the DLL it is protected. The protected DLL will need to be
in the same folder as your compiled program for it to run correctly.

Note - once your program (or dpwin32.dll) is protected you will not be able to debug
your program - after our API has been called. Our strong anti-debug code will cause
the debugger to throw an exception. If you do want to debug your code then you can
use our debug module: dpwin32_coff_debug.obj (or dpwin32debug.dll), but these should not be
used for release. See readme.txt in samples\c for restrictions concerning the debug module.

Creating your own import library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In order for MinGW to call functions in dpwin32.dll you need to link the import library
libdpwin32.a. We have created these for you, but if for some reason you need to create it
yourself then you should do the following:

1) Create a dpwin32.def file with the following format:
   LIBRARY dpwin32.dll
   EXPORTS
   <Function1>
   <Function2>

   where <Function1> etc.. are the function names that the linker complains about when you
   don't link with the import library. e.g. for dpwin32.dll you just need two functions:
   DDProtCheck@8
   DDGetNetUserList@20

   (you do not need to specify the @n part for 64-bit modules)

2) Now use dlltool to create the import library:
   dlltool --input-def dpwin32.def --output-lib libdpwin32.a -k

   Note: for our DLLs you need to use the -k option otherwise you will get an "file format
   not recognised error" when you link the import library.

